package com.itany.manager.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ApiResponse<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    private int code;
    private String message;
    private T data;

    // 成功响应（带数据）
    public static <T> ApiResponse<T> success(T data) {
        return new ApiResponse<>(200, "Success", data);
    }

    // 成功响应（无数据）
    public static ApiResponse<Void> success() {
        return new ApiResponse<>(200, "Success", null);
    }

    // 错误响应
    public static <T> ApiResponse<T> error(int code, String message) {
        return new ApiResponse<>(code, message, null);
    }

    // 分页响应
    public static <T> ApiResponse<PageResult<T>> pageSuccess(List<T> list, long total) {
        return new ApiResponse<>(200, "Success", new PageResult<>(list, total));
    }
}
